import socket
import json
import struct

sk = socket.socket()
sk.bind(("127.0.0.1", 8001))
sk.listen()
conn, addr = sk.accept()
b_len_dic = conn.recv(4)
len_dic = struct.unpack('i', b_len_dic)[0] # 获取字典的长度
str_dic = conn.recv(len_dic).decode('utf-8')
dic = json.loads(str_dic)
if dic['opt'] == 'upload':
    filename = '1'+dic['filename']
    with open(filename, 'ab') as f:
        while dic['filesize']:
            content = conn.recv(1024)
            f.write(content)
            dic['filesize'] -= len(content)
elif dic['opt'] == 'download':
    pass

conn.close()
sk.close()












